CodeLoad
CodeLoad is a customisable code page loader. It lets communities set up a system for their users to enable provided code (JavaScript/CSS), in a similar way to the extension. On a wiki using the script, user preferences can be configured on the page blankspecial=CodeLoadPrefs}} Special:BlankPage?blankspecial=CodeLoadPrefs. A link to this page is added to and to the "My tools" menu in the toolbar. Usage # Add the line below to your wiki's MediaWiki:ImportJS page: dev:CodeLoad.js # Code definitions have to be set up by the wiki's administrators. Configuration information is below. Configuring definitions Definitions are loaded from the page MediaWiki:CodeLoad-definitions.js. Some example definitions are available, which may be copy+pasted as a base for a wiki's definition page. These are configured via the JavaScript variable codeLoad.definitions, which should be an object with a unique ID (this can simply be the name of the script) for each key, and an object (the definition) as its value. Each definition object can contain the following keys: Here is an example definition excerpt for AjaxRC: "ajaxrc": { "title": "AjaxRC", "description": "Advanced auto-refreshing recent changes and watchlist (more info)", "group": "tools", "articles": [ "dev:AjaxRC/code.js" ], "preferences": { "requiresGlobalPrefs": true, "AjaxRCRefreshText": "Auto-refresh", "ajaxRefresh": 30000 } } Groups Definitions can optionally be sorted into groups on the preferences page. These are configured via the JavaScript variable codeLoad.groups, which should be an object with a unique ID for each key, and a string (the friendly name for the group, shown as a heading on the preferences page) as its value. Wikitext links may be used within the friendly group names. When a definition's group is set to a ID existing in codeLoad.groups, it will be added to that group. Any definition without a set group, or with a group ID not in codeLoad.groups, will be added to the group 'Other'. Articles The articles array should contain page names of one or more CSS (ending with .css) and/or JavaScript (ending with .js) pages. These can be either local pages (stored in the MediaWiki namespace), or pages from Dev Wiki. Imports from outside the MediaWiki namespace or from wikis other than the local wiki and Dev Wiki are not supported. Page names should not contain the MediaWiki namespace prefix. For imports from Dev Wiki, prefix the page name with dev:. Preferences Preferences (if set) should be an object, and can contain the following keys (all optional): The preferences object can also contain custom keys for that definition's preferences. A preference ID should be used for each key, and a boolean, number, or string (the default value for the preference) as its value. Friendly names for preferences can be configured via the JavaScript variable codeLoad.prefDescriptions, which should be an object with a preference ID for each key, and a string (the friendly name for the preference) as its value. Wikitext links may be used within the friendly preference names. These are shared across all definitions, and if a friendly name is available, it will be used on the preferences page in place of the preference ID. Requirements Requirements (if set) should be an object, and can contain the following keys (all optional): Intro message A optional message can be configured via the JavaScript variable codeLoad.introMessage, and will be shown below the default intro text. This may be used, for example, to provide more information about the available definitions, or to provide a link to a page with more details. Wikitext links may be used within the message. Using CodeLoad-kept preferences Preferences set/saved with CodeLoad can be accessed by calling the codeLoad.getScriptPrefs() function with a definition ID as the first argument. This is the recommended method for configuring local script preferences. Using the AjaxRC definition above as an example, the following code will set the prefs variable with the user preferences for the definition. User preferences can then be accessed via properties of the prefs variable. var prefs = codeLoad.getScriptPrefs('ajaxrc'); prefs.AjaxRCRefreshText; // will return 'Auto-refresh' prefs.ajaxRefresh; // will return 30000 requiresGlobalPrefs If preferences.requiresGlobalPrefs is set to true for a definition, that definition's preferences will be each exposed as properties on the global window object. This is available to allow scripts from Dev Wiki to be easily configurable using CodeLoad. Using the AjaxRC definition above as an example, the following code accesses user preferences for the definition. window.AjaxRCRefreshText; // will return 'Auto-refresh' window.ajaxRefresh; // will return 30000 globalPrefNamespace If preferences.requiresGlobalPrefs is set to true for a definition and preferences.globalPrefNamespace is set to a string (e.g. AjaxRCConfig), that definition's preferences will be added to a single object (namespace) with the name AjaxRCConfig, and only this object will be exposed as a property on the global window object. This may be needed for particular scripts, depending on how their preferences are configured within the script. Using the AjaxRC definition above as an example, the following code accesses user preferences for the definition. window.AjaxRCConfig.AjaxRCRefreshText; // will return 'Auto-refresh' window.AjaxRCConfig.ajaxRefresh; // will return 30000